home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / io / BufferedWriter.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  2.3 KB  |  138 lines

  1. package java.io;
  2.  
  3. import java.security.AccessController;
  4. import sun.security.action.GetPropertyAction;
  5.  
  6. public class BufferedWriter extends Writer {
  7.    private Writer out;
  8.    // $FF: renamed from: cb char[]
  9.    private char[] field_0;
  10.    private int nChars;
  11.    private int nextChar;
  12.    private static int defaultCharBufferSize = 8192;
  13.    private String lineSeparator;
  14.  
  15.    public BufferedWriter(Writer var1) {
  16.       this(var1, defaultCharBufferSize);
  17.    }
  18.  
  19.    public BufferedWriter(Writer var1, int var2) {
  20.       super(var1);
  21.       if (var2 <= 0) {
  22.          throw new IllegalArgumentException("Buffer size <= 0");
  23.       } else {
  24.          this.out = var1;
  25.          this.field_0 = new char[var2];
  26.          this.nChars = var2;
  27.          this.nextChar = 0;
  28.          this.lineSeparator = (String)AccessController.doPrivileged(new GetPropertyAction("line.separator"));
  29.       }
  30.    }
  31.  
  32.    private void ensureOpen() throws IOException {
  33.       if (this.out == null) {
  34.          throw new IOException("Stream closed");
  35.       }
  36.    }
  37.  
  38.    void flushBuffer() throws IOException {
  39.       synchronized(this.lock) {
  40.          this.ensureOpen();
  41.          if (this.nextChar != 0) {
  42.             this.out.write(this.field_0, 0, this.nextChar);
  43.             this.nextChar = 0;
  44.          }
  45.       }
  46.    }
  47.  
  48.    public void write(int var1) throws IOException {
  49.       synchronized(this.lock) {
  50.          this.ensureOpen();
  51.          if (this.nextChar >= this.nChars) {
  52.             this.flushBuffer();
  53.          }
  54.  
  55.          this.field_0[this.nextChar++] = (char)var1;
  56.       }
  57.    }
  58.  
  59.    private int min(int var1, int var2) {
  60.       return var1 < var2 ? var1 : var2;
  61.    }
  62.  
  63.    public void write(char[] var1, int var2, int var3) throws IOException {
  64.       synchronized(this.lock) {
  65.          this.ensureOpen();
  66.          if (var2 >= 0 && var2 <= var1.length && var3 >= 0 && var2 + var3 <= var1.length && var2 + var3 >= 0) {
  67.             if (var3 != 0) {
  68.                if (var3 >= this.nChars) {
  69.                   this.flushBuffer();
  70.                   this.out.write(var1, var2, var3);
  71.                } else {
  72.                   int var5 = var2;
  73.                   int var6 = var2 + var3;
  74.  
  75.                   while(var5 < var6) {
  76.                      int var7 = this.min(this.nChars - this.nextChar, var6 - var5);
  77.                      System.arraycopy(var1, var5, this.field_0, this.nextChar, var7);
  78.                      var5 += var7;
  79.                      this.nextChar += var7;
  80.                      if (this.nextChar >= this.nChars) {
  81.                         this.flushBuffer();
  82.                      }
  83.                   }
  84.  
  85.                }
  86.             }
  87.          } else {
  88.             throw new IndexOutOfBoundsException();
  89.          }
  90.       }
  91.    }
  92.  
  93.    public void write(String var1, int var2, int var3) throws IOException {
  94.       synchronized(this.lock) {
  95.          this.ensureOpen();
  96.          int var5 = var2;
  97.          int var6 = var2 + var3;
  98.  
  99.          while(var5 < var6) {
  100.             int var7 = this.min(this.nChars - this.nextChar, var6 - var5);
  101.             var1.getChars(var5, var5 + var7, this.field_0, this.nextChar);
  102.             var5 += var7;
  103.             this.nextChar += var7;
  104.             if (this.nextChar >= this.nChars) {
  105.                this.flushBuffer();
  106.             }
  107.          }
  108.  
  109.       }
  110.    }
  111.  
  112.    public void newLine() throws IOException {
  113.       this.write(this.lineSeparator);
  114.    }
  115.  
  116.    public void flush() throws IOException {
  117.       synchronized(this.lock) {
  118.          this.flushBuffer();
  119.          this.out.flush();
  120.       }
  121.    }
  122.  
  123.    public void close() throws IOException {
  124.       synchronized(this.lock) {
  125.          if (this.out != null) {
  126.             try {
  127.                this.flushBuffer();
  128.             } finally {
  129.                this.out.close();
  130.                this.out = null;
  131.                this.field_0 = null;
  132.             }
  133.  
  134.          }
  135.       }
  136.    }
  137. }
  138.